<template>
	<view>
		<!-- 收银台 -->
		<view class="edgeInsetTop"></view>
		<view class="wanl-pay">
			<view class="money bg-white">
				<text class="title">支付金额</text>
				<view class="margin-top price">
					<view class="symbol">
						<text>￥</text>
					</view>
					<input type="digit" maxlength="5" focus v-model="money"/>
					
				</view>
			</view>
			<view class="text-lg text-orange text-center">
				【消费券支付】
			</view>
			<view style="line-height: 1.8;" @tap="$wanlshop.auth('/pages/user2/reimbursement/reimbursement')">
				<view class="text-lg text-blue text-center">我的消费券余额：{{ user.reim?user.reim:0 }}</view>				
			</view>
			<button class="mix-btn wanl-bg-redorange" @tap="confirm()" :loading="loading">确认支付</button>
			<view class="footer text-center">
				<view> © 顿顿拍平台 </view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	export default {
		data() {
			return {
				loading: false,
				
				money: null,
				reim: null,
				payList: [],
				shopid: ''
			}
		},
		computed: {
			...mapState(['user'])
		},
		onLoad(option) {
			
			this.shopid = option.shopid;
			console.log(this.shopid);
			this.reim = this.user.reim;
		},
		methods: {
			//确认支付
			confirm() {
				let data = null;
				
				if(this.money <= 0){
					this.$wanlshop.msg('请输入正确的支付金额');
					return;
				}
				
				this.loading = true;
				this.wanlPay()
				
			},
			async wanlPay(){
				await uni.request({
					url: '/wanlshop/ddp/reimpay',
					method: 'POST',
					data: {
						money: this.money,
						shopid: this.shopid
					},
					success: res => {
						this.reim = this.reim - this.money
						// 关闭loading
						this.loading = false;
						this.paySuccess()
					}
				});
			},
			emptyInput(){
				this.money = null;
			},
			// 支付成功
			paySuccess(){
				this.loading = false;
				this.$store.commit('user/setUserInfo', {
					reim: this.$wanlshop.bcadd(this.$store.state.user.reim, this.reim)
				});
				this.$wanlshop.to('/pages/page/success?type=reim');
			}
		}
	}
</script>

<style>
	radio-group {
	    display: block;
	}
	.wanl-pay .money{
		padding: 25rpx 40rpx 25rpx 60rpx;
	}
	
	.wanl-pay .money .symbol{
		font-size: 60rpx;
		margin-right: 20rpx;
	}
	
	.wanl-pay .money .price{
		display: flex;
		align-items: center;
	}
	.wanl-pay .money .price input{
		/* #ifdef MP */
		height: 100rpx;
		min-height: 100rpx;
		/* #endif */
		width: 100%;
		font-size: 100rpx;
	}
</style>
